﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Experimental.Playables.TexturePlayableOutput
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Playables;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Experimental.Playables
{
  /// <summary>
  ///   <para>An IPlayableOutput implementation that will be used to manipulate textures.</para>
  /// </summary>
  [NativeHeader("Runtime/Export/Director/TexturePlayableOutput.bindings.h")]
  [NativeHeader("Runtime/Graphics/Director/TexturePlayableOutput.h")]
  [RequiredByNativeCode]
  [StaticAccessor("TexturePlayableOutputBindings", StaticAccessorType.DoubleColon)]
  [NativeHeader("Runtime/Graphics/RenderTexture.h")]
  public struct TexturePlayableOutput : IPlayableOutput
  {
    private PlayableOutputHandle m_Handle;

    public static TexturePlayableOutput Create(
      PlayableGraph graph,
      string name,
      RenderTexture target)
    {
      PlayableOutputHandle handle;
      if (!TexturePlayableGraphExtensions.InternalCreateTextureOutput(ref graph, name, out handle))
        return TexturePlayableOutput.Null;
      TexturePlayableOutput texturePlayableOutput = new TexturePlayableOutput(handle);
      texturePlayableOutput.SetTarget(target);
      return texturePlayableOutput;
    }

    internal TexturePlayableOutput(PlayableOutputHandle handle)
    {
      this.m_Handle = !handle.IsValid() || handle.IsPlayableOutputOfType<TexturePlayableOutput>() ? handle : throw new InvalidCastException("Can't set handle: the playable is not an TexturePlayableOutput.");
    }

    /// <summary>
    ///   <para>Returns an invalid TexturePlayableOutput.</para>
    /// </summary>
    public static TexturePlayableOutput Null
    {
      get => new TexturePlayableOutput(PlayableOutputHandle.Null);
    }

    public PlayableOutputHandle GetHandle() => this.m_Handle;

    public static implicit operator PlayableOutput(TexturePlayableOutput output)
    {
      return new PlayableOutput(output.GetHandle());
    }

    public static explicit operator TexturePlayableOutput(PlayableOutput output)
    {
      return new TexturePlayableOutput(output.GetHandle());
    }

    public RenderTexture GetTarget() => TexturePlayableOutput.InternalGetTarget(ref this.m_Handle);

    public void SetTarget(RenderTexture value)
    {
      TexturePlayableOutput.InternalSetTarget(ref this.m_Handle, value);
    }

    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern RenderTexture InternalGetTarget(ref PlayableOutputHandle output);

    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void InternalSetTarget(
      ref PlayableOutputHandle output,
      RenderTexture target);
  }
}
